<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/content/variable.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <%@ include file="/content/head.jsp" %>
</head>
<body>
<div class="row">
    <div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">修改分类</h3>
            </div>
            <form id="addInfo" class="form-horizontal" role="form">
                <div class="box-body">
                    <div class="form-group">
                        <label for="classificationName" class="col-sm-2 control-label">分类名称：</label>
                        <div class="col-sm-8 ">
                            <input type="text" id="classificationName" class="form-control" name="classificationName"
                                 value="${obj.classificationName}"  placeholder="分类名称">
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="classificationPicFile" class="col-sm-2 control-label">分类图片：</label>
                        <div class="col-md-8">
                            <input type="file" class="file-loading" id="classificationPicFile" accept="image/*">
                            <input type="text" class="form-control input-sm" id="classificationPicUrl"
                                   name="classificationPic" value="${obj.classificationPic}">
                        </div>
                        <div class="col-sm-2">
                            <span class="help-inline" style="color: #a94442"></span>
                        </div>
                    </div>

                    <input type="hidden" name="classificationId" value="${obj.classificationId}">
                    <div class="form-group">
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- /.row -->
<%@ include file="/content/js.jsp" %>
<script type="text/javascript">
    $(function () {
        $('#addInfo').bootstrapValidator({
            message: '此值无效',
            fields: {
                classificationName: {
                    message: '视频名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '视频名称不能为空'
                        }
                    }
                }
            }
        }).on('success.form.bv', function (e) {//点击提交之后
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            saveInfo();
        });
    })
    //视频封面上传
    $("#classificationPicFile").fileinput({
        uploadUrl: "<%=path%>/upload/uploadClassifyImg",
        browseClass: "btn btn-primary",
        enctype: 'multipart/form-data',
        autoReplace: true,
        dropZoneEnabled: false,
        browseLabel: "上传",
        showCaption: false,
        showRemove: false,
        showUpload: true,
        showZoom: false,
        maxFileCount: 1, ////表示允许同时上传的最大文件个数
        allowedFileTypes: ["image"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
        previewSettings: {
            image: {width: "auto", height: "100px"},
        },
    });
    $('#classificationPicFile').on('fileuploaded', function (event, data, previewId, index) {
        var path = data.response.initialPreviewConfig[0].extra.path;
        $("#classificationPicUrl").val(path);
    });
    $('#classificationPicFile').on('filedeleted', function (event, key, jqXHR, data) {
        if ($("#classificationPicUrl").val() == data.path)
            $("#classificationPicUrl").val('');
    });
        function saveInfo() {
            $.post("<%=path%>/classification/edit",
                $("#addInfo").serialize()
                , function (data) {
                    if (data.missage == "success") {
                        modalMsg("新增成功", "success");
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else if (data.missage == "error") {
                        modalMsg("新增失败", "error");
                    } else {
                        modalMsg("更新失败", "error");
                    }
                }
            );
        }

</script>
</body>
</html>